package com.luoxiang.socialandroid.adapter;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.luoxiang.socialandroid.R;
import com.luoxiang.socialandroid.bean.CallContent;
import com.luoxiang.socialandroid.bean.HostCallContent;

import java.util.List;

public class Popupwindow2Adapter extends RecyclerView.Adapter<Popupwindow2Adapter.ViewHolder>{
    private List<HostCallContent> list;

    public Popupwindow2Adapter(List<HostCallContent> list) {
        this.list = list;
    }

    public static interface OnAddClickListener {
        void onItemClicks(int id, String content);
    }

    Popupwindow2Adapter.OnAddClickListener onItemAddClick;

    public void setOnAddClickListener(Popupwindow2Adapter.OnAddClickListener onItemAddClick) {
        this.onItemAddClick = onItemAddClick;
    }

    @NonNull
    @Override
    public Popupwindow2Adapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_popup, parent, false);
        Popupwindow2Adapter.ViewHolder holder = new Popupwindow2Adapter.ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull Popupwindow2Adapter.ViewHolder holder, int position) {
        holder.tv_contenthz.setText(list.get(position).getContent());
        if (position == 0) {
            holder.tv_contenthz.setTextColor(Color.parseColor("#835DFF"));
        } else {
            holder.tv_contenthz.setTextColor(Color.parseColor("#333333"));
        }
        holder.liner_zhaohuyu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onItemAddClick.onItemClicks(list.get(position).getId(),list.get(position).getContent());
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder {
        private TextView tv_contenthz;
        private LinearLayout liner_zhaohuyu;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_contenthz = itemView.findViewById(R.id.tv_contenthz);
            liner_zhaohuyu = itemView.findViewById(R.id.liner_zhaohuyu);
        }
    }
}
